﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ICTBilling;

/// <summary>
/// Summary description for tbLocation
/// </summary>
public partial class tbLocation : IValidate
{
    public List<ExceptionHandler> Validate(ChangeAction changeAction)
    {
        List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
        try
        {
            if (changeAction == ChangeAction.Insert ||
                changeAction == ChangeAction.Update)
            {
                if (changeAction == ChangeAction.Update && this.PkLocationID == null)
                    ExecutionCollection.Add(new ExceptionHandler("PkLocationID", "شناسه موقعیت مکانی", ICTBilling.ExceptionType.NullArgumant));

                if (this.LocationName == null)
                    ExecutionCollection.Add(new ExceptionHandler("LocationName", "عنوان موقعیت", ICTBilling.ExceptionType.NullArgumant));

                if (this.FkParentID == null)
                    ExecutionCollection.Add(new ExceptionHandler("FkParentID", "شناسه پدر", ICTBilling.ExceptionType.NullArgumant));

                if (this.Type == null)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع محل", ICTBilling.ExceptionType.NullArgumant));
                else if (this.Type > 255 || this.Type < 1)
                    ExecutionCollection.Add(new ExceptionHandler("Type", "نوع محل", ICTBilling.ExceptionType.ShortFormat));
                else
                {
                    try
                    {
                        byte.Parse(this.Type.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("Type", "نوع محل", ICTBilling.ExceptionType.ShortFormat));
                    }
                }

            }
        }
        catch (Exception _Exception)
        {
            ExecutionCollection.Add(new ExceptionHandler(_Exception));
        }
        return ExecutionCollection;
    }
}